var t = require("../../@babel/runtime/helpers/typeof");

module.exports = function(e) {
    var n = {};
    function i(t) {
        if (n[t]) return n[t].exports;
        var u = n[t] = {
            i: t,
            l: !1,
            exports: {}
        };
        return e[t].call(u.exports, u, u.exports, i), u.l = !0, u.exports;
    }
    return i.m = e, i.c = n, i.d = function(t, e, n) {
        i.o(t, e) || Object.defineProperty(t, e, {
            enumerable: !0,
            get: n
        });
    }, i.r = function(t) {
        "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, {
            value: "Module"
        }), Object.defineProperty(t, "__esModule", {
            value: !0
        });
    }, i.t = function(e, n) {
        if (1 & n && (e = i(e)), 8 & n) return e;
        if (4 & n && "object" === t(e) && e && e.__esModule) return e;
        var u = Object.create(null);
        if (i.r(u), Object.defineProperty(u, "default", {
            enumerable: !0,
            value: e
        }), 2 & n && "string" != typeof e) for (var l in e) i.d(u, l, function(t) {
            return e[t];
        }.bind(null, l));
        return u;
    }, i.n = function(t) {
        var e = t && t.__esModule ? function() {
            return t.default;
        } : function() {
            return t;
        };
        return i.d(e, "a", e), e;
    }, i.o = function(t, e) {
        return Object.prototype.hasOwnProperty.call(t, e);
    }, i.p = "", i(i.s = 0);
}([ function(t, e, n) {
    var i, u = n(1), l = (i = u) && i.__esModule ? i : {
        default: i
    };
    Component({
        methods: {
            getBarrageInstance: function(t) {
                return t.comp = this, this.barrage = new l.default(t), this.barrage;
            },
            onAnimationend: function(t) {
                var e = t.currentTarget.dataset, n = e.tunnelid, i = e.bulletid;
                this.barrage.animationend({
                    tunnelId: n,
                    bulletId: i
                });
            },
            onTapBullet: function(t) {
                var e = t.currentTarget.dataset, n = e.tunnelid, i = e.bulletid;
                this.barrage.tapBullet({
                    tunnelId: n,
                    bulletId: i
                });
            }
        }
    });
}, function(t, e, n) {
    function i(t, e) {
        if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function");
    }
    e.__esModule = !0;
    var u = n(2), l = u.substring, o = u.getRandom, s = u.getFontSize, a = function() {
        function t() {
            var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
            i(this, t), this.bulletId = e.bulletId;
        }
        return t.prototype.addContent = function() {
            var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, e = {
                duration: 0,
                passtime: 0,
                content: "",
                color: "#000000",
                width: 0,
                height: 0,
                image: {},
                paused: !1
            };
            Object.assign(this, e, t);
        }, t.prototype.removeContent = function() {
            this.addContent({});
        }, t;
    }(), r = function() {
        function t() {
            var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
            i(this, t);
            var n = {
                tunnelId: 0,
                height: 0,
                width: 0,
                safeGap: 4,
                maxNum: 10,
                bullets: [],
                last: -1,
                bulletStatus: [],
                disabled: !1,
                sending: !1
            };
            Object.assign(this, n, e), this.bulletStatus = new Array(this.maxNum).fill(0);
            for (var u = 0; u < this.maxNum; u++) this.bullets.push(new a({
                bulletId: u
            }));
        }
        return t.prototype.disable = function() {
            this.disabled = !0, this.last = -1, this.sending = !1, this.bulletStatus = new Array(this.maxNum).fill(1), 
            this.bullets.forEach(function(t) {
                return t.removeContent();
            });
        }, t.prototype.enable = function() {
            this.disabled && (this.bulletStatus = new Array(this.maxNum).fill(0)), this.disabled = !1;
        }, t.prototype.clear = function() {
            this.last = -1, this.sending = !1, this.bulletStatus = new Array(this.maxNum).fill(0), 
            this.bullets.forEach(function(t) {
                return t.removeContent();
            });
        }, t.prototype.getIdleBulletIdx = function() {
            return this.bulletStatus.indexOf(0);
        }, t.prototype.getIdleBulletNum = function() {
            var t = 0;
            return this.bulletStatus.forEach(function(e) {
                0 === e && t++;
            }), t;
        }, t.prototype.addBullet = function(t) {
            if (!this.disabled) {
                var e = this.getIdleBulletIdx();
                e >= 0 && (this.bulletStatus[e] = 1, this.bullets[e].addContent(t));
            }
        }, t.prototype.removeBullet = function(t) {
            this.disabled || (this.bulletStatus[t] = 0, this.bullets[t].removeContent());
        }, t;
    }(), h = function() {
        function t() {
            var e = this, n = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
            i(this, t), this._promise = new Promise(function(t) {
                Object.assign(e, {
                    width: 300,
                    height: 150,
                    duration: 10,
                    lineHeight: 1.2,
                    padding: [ 0, 0, 0, 0 ],
                    alpha: 1,
                    font: "10px sans-serif",
                    mode: "separate",
                    range: [ 0, 1 ],
                    tunnelShow: !1,
                    tunnelMaxNum: 30,
                    maxLength: 50,
                    safeGap: 4,
                    enableTap: !1,
                    tunnelHeight: 0,
                    tunnelNum: 0,
                    tunnels: [],
                    idleTunnels: null,
                    enableTunnels: null,
                    distance: 2e3,
                    comp: null
                }, n), e.comp.createSelectorQuery().select(".barrage-area").boundingClientRect(function(n) {
                    e.width = n.width, e.height = n.height, e.init(), t();
                }).exec();
            });
        }
        return t.prototype.resize = function() {
            var t = this;
            return this._promise.then(function() {
                t.comp.createSelectorQuery().select(".barrage-area").boundingClientRect(function(e) {
                    t.width = e.width, t.height = e.height;
                    var n = t._isActive;
                    t.close(function() {
                        t.init(), n && setTimeout(function() {
                            t.open();
                        }, 2e3);
                    });
                }).exec();
            });
        }, t.prototype.init = function() {
            this.fontSize = s(this.font), this.idleTunnels = new Set(), this.enableTunnels = new Set(), 
            this.tunnels = [], this.availableHeight = this.height - this.padding[0] - this.padding[2], 
            this.tunnelHeight = this.fontSize * this.lineHeight, this.tunnelNum = Math.floor(this.availableHeight / (this.tunnelHeight + 10));
            for (var t = 0; t < this.tunnelNum; t++) this.idleTunnels.add(t), this.enableTunnels.add(t), 
            this.tunnels.push(new r({
                width: this.width,
                height: this.tunnelHeight,
                safeGap: this.safeGap,
                maxNum: this.tunnelMaxNum,
                tunnelId: t
            }));
            this.comp.setData({
                tunnelShow: this.tunnelShow,
                tunnels: this.tunnels,
                font: this.font,
                alpha: this.alpha,
                padding: this.padding.map(function(t) {
                    return t + "px";
                }).join(" ")
            }), this.setRange();
        }, t.prototype.setRange = function(t) {
            var e = this;
            return this._promise.then(function() {
                var n = (t = t || e.range)[0] * e.tunnelNum, i = t[1] * e.tunnelNum, u = new Set(), l = new Set();
                e.tunnels.forEach(function(t, o) {
                    if (o >= n && o < i) {
                        var s = t.disabled;
                        t.enable(), l.add(o), (s || e.idleTunnels.has(o)) && u.add(o);
                    } else t.disable();
                }), e.idleTunnels = u, e.enableTunnels = l, e.range = t, e.comp.setData({
                    tunnels: e.tunnels
                });
            });
        }, t.prototype.setFont = function(t) {
            var e = this;
            return this._promise.then(function() {
                "string" == typeof t && (e.font = t, e.comp.setData({
                    font: t
                }));
            });
        }, t.prototype.setAlpha = function(t) {
            var e = this;
            return this._promise.then(function() {
                "number" == typeof t && (e.alpha = t, e.comp.setData({
                    alpha: t
                }));
            });
        }, t.prototype.setDuration = function(t) {
            var e = this;
            return this._promise.then(function() {
                "number" == typeof t && (e.duration = t, e.clear());
            });
        }, t.prototype.open = function() {
            var t = this;
            return this._promise.then(function() {
                t._isActive = !0;
            });
        }, t.prototype.close = function(t) {
            var e = this;
            return this._promise.then(function() {
                e._isActive = !1, e.clear(t);
            });
        }, t.prototype.clear = function(t) {
            this.tunnels.forEach(function(t) {
                return t.clear();
            }), this.idleTunnels = new Set(this.enableTunnels), this.comp.setData({
                tunnels: this.tunnels
            }, function() {
                "function" == typeof t && t();
            });
        }, t.prototype.addData = function() {
            var t = this, e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [];
            return this._promise.then(function() {
                t._isActive && (e.forEach(function(e) {
                    e.content = l(e.content, t.maxLength), t.addBullet2Tunnel(e);
                }), t.comp.setData({
                    tunnels: t.tunnels
                }, function() {
                    t.updateBullets();
                }));
            });
        }, t.prototype.send = function() {
            var t = this, e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
            return this._promise.then(function() {
                if (0 !== t.enableTunnels.size) var n = setInterval(function() {
                    t.getIdleTunnel() && (t.addData([ e ]), clearInterval(n));
                }, 16);
            });
        }, t.prototype.addBullet2Tunnel = function() {
            var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, e = this.getIdleTunnel();
            if (null !== e) {
                var n = e.tunnelId;
                e.addBullet(t), 0 === e.getIdleBulletNum() && this.removeIdleTunnel(n);
            }
        }, t.prototype.updateBullets = function() {
            var t = this;
            this.comp.createSelectorQuery().selectAll(".bullet-item").boundingClientRect(function(e) {
                for (var n = 0; n < e.length; n++) {
                    var i = e[n].dataset, u = i.tunnelid, l = i.bulletid, o = t.tunnels[u].bullets[l];
                    o.width = e[n].width, o.height = e[n].height;
                }
                t.animate();
            }).exec();
        }, t.prototype.animate = function() {
            var t = this;
            this.tunnels.forEach(function(e) {
                t.tunnelAnimate(e);
            });
        }, t.prototype.tunnelAnimate = function(t) {
            var e = this;
            if (!t.disabled && !t.sending) {
                var n = (t.last + 1) % t.maxNum, i = t.bullets[n];
                if (i && (i.content || i.image)) {
                    var u;
                    t.sending = !0, t.last = n;
                    var l = this.distance * this.duration / (this.distance + i.width), o = i.width + 100;
                    i.duration = "overlap" === this.mode ? l : this.duration, i.passtime = Math.ceil(o * i.duration * 1e3 / this.distance), 
                    this.comp.setData(((u = {})["tunnels[" + t.tunnelId + "].bullets[" + i.bulletId + "]"] = i, 
                    u), function() {
                        setTimeout(function() {
                            t.sending = !1, e.tunnelAnimate(t);
                        }, i.passtime);
                    });
                }
            }
        }, t.prototype.showTunnel = function() {
            this.comp.setData({
                tunnelShow: !0
            });
        }, t.prototype.hideTunnel = function() {
            this.comp.setData({
                tunnelShow: !1
            });
        }, t.prototype.removeIdleTunnel = function(t) {
            this.idleTunnels.delete(t);
        }, t.prototype.addIdleTunnel = function(t) {
            this.idleTunnels.add(t);
        }, t.prototype.getEnableTunnel = function() {
            if (0 === this.enableTunnels.size) return null;
            var t = Array.from(this.enableTunnels), e = o(t.length);
            return this.tunnels[t[e]];
        }, t.prototype.getIdleTunnel = function() {
            if (0 === this.idleTunnels.size) return null;
            var t = Array.from(this.idleTunnels), e = o(t.length);
            return this.tunnels[t[e]];
        }, t.prototype.animationend = function(t) {
            var e, n = t.tunnelId, i = t.bulletId, u = this.tunnels[n], l = u.bullets[i];
            u && l && (u.removeBullet(i), this.addIdleTunnel(n), this.comp.setData(((e = {})["tunnels[" + n + "].bullets[" + i + "]"] = l, 
            e)));
        }, t.prototype.tapBullet = function(t) {
            var e;
            if (this.enableTap) {
                var n = t.tunnelId, i = t.bulletId, u = this.tunnels[n].bullets[i];
                u.paused = !u.paused, this.comp.setData(((e = {})["tunnels[" + n + "].bullets[" + i + "]"] = u, 
                e));
            }
        }, t;
    }();
    e.default = h;
}, function(t, e, n) {
    function i(t) {
        return t.replace(/[^\x00-\xff]/g, "aa").length;
    }
    t.exports = {
        getStrLen: i,
        substring: function(t, e) {
            if (!t) return "";
            if (e >= i(t)) return t;
            for (var n = 0, u = "", l = 0; l < t.length; l++) {
                var o = t.charAt(l);
                if (u += o, (n = /[^\x00-\xff]/i.test(o) ? n + 2 : n + 1) >= e) break;
            }
            return u;
        },
        getRandom: function() {
            var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 10, e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
            return Math.floor(Math.random() * (t - e) + e);
        },
        getFontSize: function(t) {
            var e = t.match(/(\d+)(px)/i);
            return e && e[1] || 10;
        }
    };
} ]);